package com.crayfish.quduo.ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.crayfish.quduo.R;
import com.crayfish.quduo.model.LaiFuDaoBean;
import com.crayfish.quduo.utils.ImageUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by crayfish on 2016/12/28.
 */
public class LaiFuDaoAdapter extends RecyclerView.Adapter<LaiFuDaoAdapter.ViewHolder> {

    private Context mContext;
    private List<LaiFuDaoBean> datas;

    public LaiFuDaoAdapter(Context context) {
        super();
        this.mContext = context;
        datas = new ArrayList<LaiFuDaoBean>();
    }

    public void addAll(List<LaiFuDaoBean> datas){
        this.datas = datas;
        notifyDataSetChanged();
    }

    public void clear(){
        this.datas.clear();
        notifyDataSetChanged();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_meipai_list,parent,false);
        ViewHolder vh = new ViewHolder(view);
        return vh;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
//        ImageUtil.imageLoad(mContext,datas.get(position).getThumburl(),holder.iv_cover_pic);
        holder.txt_title.setText(datas.get(position).getTitle());
        holder.txt_comment.setText("浏览量：1000");
        holder.txt_laud.setText("·点赞数：500");
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder{
        ImageView iv_cover_pic;
        TextView txt_title;
        TextView txt_comment;
        TextView txt_laud;
        public ViewHolder(View itemView) {
            super(itemView);
            iv_cover_pic = (ImageView)itemView.findViewById(R.id.iv_cover_pic);
            txt_title = (TextView)itemView.findViewById(R.id.txt_title);
            txt_comment = (TextView)itemView.findViewById(R.id.txt_comment);
            txt_laud = (TextView)itemView.findViewById(R.id.txt_laud);
        }
    }
}
